﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Hangjing.Common;
using Newtonsoft.Json;
using System.Text;
using System.IO;
using Hangjing.Model;
using Hangjing.DBUtility;
using Hangjing.SQLServerDAL;
using System.Collections.Specialized;
using Hangjing.EleAPI;

public partial class api_eleService_api : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Clear();

        int push_action = HjNetHelper.GetPostParam("push_action", 0);






        //HJlog.toLog("eleme_order_ids" + eleme_order_ids + "xxxx");

        switch (push_action)
        {
            case 1: //新订单推送
                {
                    string eleme_order_ids = HjNetHelper.GetPostParam("eleme_order_ids");
                    if (eleme_order_ids.Length > 0)
                    {
                        baseEleAPI api = new baseEleAPI();
                        api.init(Context);

                        string[] order_ids = eleme_order_ids.Split(',');
                        foreach (var item in order_ids)
                        {
                            eleOrder orderinfo = api.QueryOrderByID(item);
                            if (orderinfo.data != null)
                            {
                                api.AddOrder(orderinfo);


                            }
                        }
                    }

                }

                break;
            case 2://订单状态变更推送

                string eleme_order_id = HjNetHelper.GetPostParam("eleme_order_id");
                string new_status = Request["new_status"].ToString();
                if ("-1" == new_status)//取消
                {

                    eleme_order_id = "e" + eleme_order_id;

                    new  Custorder().AddOrderRecord(eleme_order_id, 5, "ele", "饿了么取消了订单");
                    ////订单取消
                    string sql = "update Custorder set OrderStatus=5 where OrderID='" + eleme_order_id + "';update shopeleCustorder set OrderStatus=5 where OrderID='" + eleme_order_id + "'";
                    WebUtility.excutesql(sql);


                }


                break;
            case 3://退单状态推送
                break;
            case 4://订单配送状态推送
                break;
            default:
                break;
        }

        StringBuilder sb = new StringBuilder();

        NameValueCollection collection;
        //post data
        if (Request.HttpMethod == "POST")
        {
            collection = Request.Form;
            foreach (string k in collection)
            {
                string v = (string)collection[k];
                sb.Append(k + "=" + v + "@@\r\n");

            }
        }
        //query string
        collection = Request.QueryString;
        foreach (string k in collection)
        {
            string v = (string)collection[k];
            sb.Append(k + "=" + v + "\r\n");
        }

        HJlog.toLog("\r\nele来消息了哈" + sb.ToString());

        Response.Write("{\"message\": \"ok\"}");

        Response.End();
    }
}